import { Config } from "./config.js"
import { Input } from "./input.js";
import { Translator } from "./translate.js";
import { callback } from "./output.js";

function start() {
    let config = window.config = new Config("config");
    let input = window.input = new Input();

    config.addConfigRequired(input);
    
    // input div
    let api_input = window.api_input = document.getElementById("api_input");
    let text_input = window.text_input = document.getElementById("text_input");

    let trans_button = window.trans_button = document.getElementById("trans_button");
    trans_button.onclick = trans_click;

    config.getConfig();
}

function trans_click() {
    window.input.api = window.api_input.value;
    window.config.store(window.input.api, window.text_input);

    new Translator(window.input.api, window.text_input.value, callback).run()
}

function test() {
    let data = [
            {
                after: "这",
                original: "是"
            },
            {
                after: "所以",
                original: "故"
            },
            {
                after: "内圣外王",
                original: "内圣外王"
            }
        ]
    callback(data);
}

window.onload = start;
window.test = test;